package cn.com.css.taxInspection.system.controller;

import cn.com.css.taxInspection.common.constants.TaxConstants;
import cn.com.css.taxInspection.system.service.impl.HttpSessionService;
import cn.com.css.taxInspection.util.TsBqUtils;
import com.baomidou.dynamic.datasource.annotation.DS;
import io.swagger.annotations.Api;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 视图
 *
 * @author wenbin
 * @version V1.0
 * @date 2020年3月18日
 */
@Api(tags = "服务端口视图")
@Controller
@RequestMapping("/index")
public class IndexServerController {
    @Autowired
    private HttpSessionService httpSessionService;


    @GetMapping("/login")
    public String logout() {
        Subject subject = SecurityUtils.getSubject();
        if (subject.isAuthenticated()) {
            return "redirect:/index/home";
        }
        return "login";
    }

    //首页
    @GetMapping("/home")
    public String home(Model model, String userId, String taxcode, String token, String roles) {
        String resView = "";
        model.addAttribute("userId", userId);
        model.addAttribute("taxcode", taxcode);
        model.addAttribute("token", token);
        String currentRolesId = httpSessionService.getCurrentRolesIdNew(token, userId);
        if (TsBqUtils.isNotNull(roles)) {
            if (roles.contains(TaxConstants.SYSTEM_MGR_ID) || roles.contains(TaxConstants.DIRECTO_ID)
                    || roles.contains(TaxConstants.SJLDG_ID)
                    || roles.contains(TaxConstants.JCJLDG_ID)
                    || roles.contains(TaxConstants.KQYJCJLDG_ID)
            ) {
                resView = "home";
            }
            // 检查科科长岗位
            else if (roles.contains(TaxConstants.SECTION_CHIEF_ID)) {
                resView = "home_selectchief";
            } else {
                resView = "home_clerk";
            }
        } else {

            if (TsBqUtils.isNull(currentRolesId)) {
                resView = "home_clerk";
            } else {
                if (currentRolesId.contains(TaxConstants.SYSTEM_MGR_ID) || currentRolesId.contains(TaxConstants.DIRECTO_ID)
                        || currentRolesId.contains(TaxConstants.SJLDG_ID)
                        || currentRolesId.contains(TaxConstants.JCJLDG_ID)
                        || currentRolesId.contains(TaxConstants.KQYJCJLDG_ID)
                ) {
                    resView = "home";
                }
                // 检查科科长岗位
                else if (currentRolesId.contains(TaxConstants.SECTION_CHIEF_ID)) {
                    resView = "home_selectchief";
                } else {
                    resView = "home_clerk";
                }
            }
        }
        return resView;
    }

    @GetMapping("/users/password")
    public String updatePassword() {
        return "users/update_password";
    }

    @GetMapping("/users/info")
    public String userDetail(Model model) {
        model.addAttribute("flagType", "edit");
        return "users/user_edit";
    }

    @GetMapping("/users/identity")
    public String userIdentity(Model model) {
        model.addAttribute("flagType", "edit");
        return "users/user_identity";
    }

    @GetMapping("/menus")
    public String menusList() {

        return "menus/menu_list";
    }

    @GetMapping("/roles")
    public String roleList() {
        return "roles/role_list";
    }

    @GetMapping("/users")
    public String userList() {
        return "users/user_list";
    }

    @GetMapping("/logs")
    public String logList() {
        return "logsmanage/log_list";
    }

    @GetMapping("/depts")
    public String deptList() {
        return "depts/dept_list";
    }

    @GetMapping("/403")
    public String error403() {
        return "error/403";
    }

    @GetMapping("/404")
    public String error404() {
        return "error/404";
    }

    @GetMapping("/500")
    public String error405() {
        return "error/500";
    }

    @GetMapping("/main")
    public String indexHome() {
        return "index";
    }

    /*本市案件*/
    @GetMapping("/anjian")
    public String anjian() {
        return "anjian";
    }

    /*查补入库*/
    @GetMapping("/ruku")
    public String ruku() {
        return "ruku";
    }

    /*积案进展*/
    @GetMapping("/jajz")
    public String jajz() {
        return "HomeNavigationBar/jajz";
    }

    /*稽比析*/
    @GetMapping("/jbx")
    public String jbx() {
        return "HomeNavigationBar/jbx";
    }

    /*新-工作质效*/
    @GetMapping("/gzzx")
    public String gzzx() {
        return "HomeNavigationBar/gzzx";
    }

    /*智慧报表*/
    @GetMapping("/zhbb")
    public String zhbg() {
        return "HomeNavigationBar/zhbb";
    }

    /*沈阳市税务稽查数据比*/
    @GetMapping("/syswjcsjb")
    public String syswjcsjb() {
        return "HomeNavigationBar/syswjcsjb";
    }

    @GetMapping("/jian")
    public String jian() {
        return "jian";
    }

    @GetMapping("/jiannew")
    public String jiannew() {
        return "jiannew";
    }

    @GetMapping("/error405")
    public String errornew() {
        return "error405";
    }

    @GetMapping("/mainselectchief")
    public String indexHomeSelectchief() {
        return "main_selectchief";
    }

    @GetMapping("/mainclerk")
    public String indexHomeclerk() {
        return "main_clerk";
    }

    @GetMapping("/about")
    public String about() {
        return "about";
    }

    @GetMapping("/build")
    public String build() {
        return "build";
    }

    @GetMapping("/sysContent")
    public String sysContent() {
        return "syscontent/list";
    }

    @GetMapping("/sysDict")
    public String sysDict() {
        return "sysdict/list";
    }

    @GetMapping("/sysGenerator")
    public String sysGenerator() {
        return "generator/list";
    }

    @GetMapping("/sysJob")
    public String sysJob() {
        return "sysjob/list";
    }

    @GetMapping("/xtrw")
    public String xtrw() {
        return "sysjob/xtrw";
    }

    @GetMapping("/sysJobLog")
    public String sysJobLog() {
        return "sysjoblog/list";
    }

    @GetMapping("/sysFiles")
    public String sysFiles() {
        return "sysfiles/list";
    }

    @GetMapping("/fcjyJbxx2")
    public String fcjyJbxx2() {
        return "fdcyth/fcjyJbxx2";
    }

    @GetMapping("/fcythFxTcpdJg")
    public String fcythFxTcpdJg() {
        return "fdcyth/fcythFxTcpdJg";
    }

    @GetMapping("/fcythFxyjCynx")
    public String fcythFxyjCynx() {
        return "fdcyth/fcythFxyjCynx";
    }

    @GetMapping("/fcythFxyjJsyj")
    public String fcythFxyjJsyj() {
        return "fdcyth/fcythFxyjJsyj";
    }

    @GetMapping("/ajyj")
    public String ajyj() {
        return "ajyj";
    }

    @GetMapping("/xafx")
    public String xafx() {
        return "xafx";
    }

    @GetMapping("/aizs")
    public String aizs() {
        return "layim/ai";
    }

}
